package com.itheima.mapper;

import com.itheima.VO.OrderSettingVO;
import com.itheima.pojo.OrderSetting;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersettingMapper {

    //根据日期修改可预约人数
    @Update("update t_ordersetting set number = #{number} where orderDate = #{orderDate}")
    int editNumberByOrderDate(OrderSetting OrderSetting);

   //根据日期修改已预约人数
//    @Select("select `id` AS `date`,`number`,`reservations` from t_ordersetting where orderDate like concat(#{month},'%')")
//    List<OrderSettingVO> getOrderSettingByMonth(String month);


    // 根据日期修改已预约人数
    List<OrderSetting> getOrdersSettingByMonth(String month);

//    @Insert("INSERT INTO ordersetting (orderDate, number) VALUES (#{orderDate}, #{number})")
//    int saveAll(OrderSetting orderSettings);
    void saveAll(List<OrderSetting> orderSettings);

    //今日预约人数
    @Select("SELECT SUM(reservations) AS reservations FROM t_ordersetting where orderDate = #{reportDate}")
    Integer todayOrderNumber(LocalDate reportDate);

    //本周预约人数
    @Select("SELECT SUM(reservations) AS reservations FROM t_ordersetting where orderDate between #{startDate} and #{endDate}")
    Integer thisWeekOrderNumber(LocalDate startDate,LocalDate endDate);

    //本月预约人数
    @Select("SELECT SUM(reservations) AS reservations FROM t_ordersetting where orderDate between #{startDate} and #{endDate}")
    Integer thisMonthOrderNumber(LocalDate startDate,LocalDate endDate);

    //热门套餐
    @Select("SELECT COUNT(o.id) AS setmeal_count,s.name AS `name` " +
            "FROM t_order o LEFT JOIN t_setmeal s  ON o.setmeal_id = s.id GROUP BY `name`")
    List<Map<String, Object>> getHotSetmeal();

}
